'use strict';

/* Controllers */
// signin controller
app.controller('SigninFormController', ['$scope', '$http', '$state', 'apiService', '$cookieStore', '$timeout', function ($scope, $http, $state, apiService, $cookieStore, $timeout) {
  $scope.user = {};
  $scope.authError = null;
  $cookieStore.remove('cy__chongzhi');

  $scope.login = function () {
    $scope.authError = null;
    $scope.btn_disabled = true;
    // 提交数据
    apiService.post({
      modelName: 'account',
      apiName: 'loginAccount'
    }, $scope.user, function (data) {
      $scope.btn_disabled = false;
      if (data.code == 200) {
        $cookieStore.put('cy__chongzhi', data['data']);
        $scope.authError = data['msc'];
        $timeout(function () {
          $state.go('app.dashboard-v1');
        }, 300);
      } else {
        $scope.authError = data['msc'];
      }
    }, function (err) {
      $scope.btn_disabled = false;
      console.log(err);
      $scope.authError = '服务器出小差咯！';
    });

  };
}]);